package com.zjhd.sealcutting.config;

import com.zjhd.sealcutting.Interceptor.SessionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * TODO 来登录拦截器
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/11/24 13:36
 */
@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    /**
     * TODO  登陆校验的拦截器注入
     * @author wangchao
     * @date 2020/11/24 13:37
     * @param
     * @return
     */
    @Autowired
    private SessionInterceptor sessionInterceptor;

    /**
     * TODO 这个方法用来注册拦截器，我们自己写好的拦截器需要通过这里添加注册才能生效
     * @author wangchao
     * @date 2020/11/24 13:38
     * @param
     * @return
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(sessionInterceptor).addPathPatterns("/**").excludePathPatterns("/login/signIn","/login/checkMobile","/login/sendMobileSmsVerificationCode","/sms/queryMobileSmsVerificationCode","/area/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");;
    }

    /**
     * TODO 这个方法是用来配置静态资源的，比如html，js，css，等等
     * @author wangchao
     * @date 2020/11/24 13:39
     * @param
     * @return
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
    }
}
